package com.tju.Service.impl;

import com.tju.IDao.UserRolesMapper;
import com.tju.Util.Constants;
import com.tju.Util.ResultDO;
import com.tju.model.MenuObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import com.tju.Service.UserRoleService;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by xiangyang on 2016/12/28.
 */
@Slf4j
@Service("userRoleServiceImpl")
public class UserRoleServiceImpl implements UserRoleService {

    @Resource
    UserRolesMapper userRolesMapper;

    @Override
    public ResultDO<List<String>>  getUserRolesByUserId(int userId) {
        log.warn("query all roles by userId :");
        ResultDO<List<String>> resultDO = new ResultDO<List<String>>();
        try {
            List<String> userRolesList = userRolesMapper.selectRolesByUserID(userId);
            resultDO.setModule(userRolesList);
            resultDO.setSuccess(true);
        } catch (Throwable e) {
            log.error("query all alarms  filed.", e);
            resultDO.setErrorCode(Constants.getErrCode(Constants.ERR_DB_EXCEPTION, Constants.DEFAULT_ERROR_MESSAGE));
        }
        return resultDO;
    }

    @Override
    public ResultDO<List<MenuObject>> selectMenusByUserID(int userId) {
        log.warn("query all roles by userId :");
        ResultDO<List<MenuObject>> resultDO = new ResultDO<List<MenuObject>>();
        try {
            List<MenuObject> userRolesList = userRolesMapper.selectMenusByUserID(userId);
            resultDO.setModule(userRolesList);
            resultDO.setSuccess(true);
        } catch (Throwable e) {
            log.error("query all alarms  filed.", e);
            resultDO.setErrorCode(Constants.getErrCode(Constants.ERR_DB_EXCEPTION, Constants.DEFAULT_ERROR_MESSAGE));
        }
        return resultDO;
    }
}
